package com.jayqqaa12.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;

import com.jayqqaa12.Code;
import com.jayqqaa12.oauth2.OauthLogin;

public class OauthLoginImpl implements OauthLogin {

	
	public int login(String username, String pwd) {
		int code =200;
		UsernamePasswordToken token = new UsernamePasswordToken(username, pwd);
		Subject subject = SecurityUtils.getSubject();
		if (!subject.isAuthenticated()) {

			try {
				subject.login(token);
			} catch (UnknownAccountException e) {
				code=(Code.USER_NOT_EXIT.code);
				e.printStackTrace();
			} catch (IncorrectCredentialsException e) {
				code=(Code.USER_PWD_ERROR.code);
				e.printStackTrace();
			} catch (LockedAccountException e) {
				code=(Code.USER_FRRZE.code);
				e.printStackTrace();
			} catch (ExcessiveAttemptsException e) {
				code=(Code.USER_ATTEMPT.code);
				e.printStackTrace();
			} catch (AuthenticationException e) {
				code=(Code.USER_AUTH.code);
				e.printStackTrace();
			} catch (Exception e) {
				code=(Code.SERVER_ERROR.code);
				e.printStackTrace();
			}
		}
		
		return code;

	}

}
